
import org.apache.ibatis.session.RowBounds;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import per.kongtouxu.Util.CommonMethod;
import per.kongtouxu.dao.*;
import per.kongtouxu.domain.pojo.*;
import per.kongtouxu.domain.vo.V_Admin;
import per.kongtouxu.service.AdminService;
import per.kongtouxu.service.Impl.AdminServiceImpl;
import per.kongtouxu.service.Impl.MenuServiceImpl;

import java.io.IOException;
import java.util.Date;
import java.util.List;

public class DaoTest {
    @Test
    public void test01(){
        AdminServiceImpl adminService = new AdminServiceImpl();
        Admin admin = new Admin();
        admin.setAdminName("zhangsan");
        admin.setAdminPwd("123456");
        Admin login = adminService.login(admin);
        System.out.println(login);
    }

    @Test
    public void test02(){
        MenuServiceImpl menuService = new MenuServiceImpl();
        List<Menu> menuByAdminId = menuService.findMenuByAdminId(101);
        System.out.println(menuByAdminId);
    }

    @Test
    public void test03() throws IOException {
        SqlSession sqlSession = CommonMethod.getSqlSession();
        UserDao userDao = sqlSession.getMapper(UserDao.class);
        Integer countUserByPage = userDao.findCountUserByPage(null, null, null, null, null);
        System.out.println(countUserByPage);
        List<User> userList = userDao.findUserByPage(null, null, null, null, null, new RowBounds(0, 10));
        System.out.println(userList);
        sqlSession.close();
    }
    @Test
    public void test04(){
        SqlSession sqlSession = CommonMethod.getSqlSession();
        AdminLogDao mapper = sqlSession.getMapper(AdminLogDao.class);
        AdminLog adminLog = new AdminLog(null,101,"禁用前台用户",new Date());
        Integer integer = mapper.saveAdminLog(adminLog);
        sqlSession.commit();
        System.out.println(integer);
    }
    @Test
    public void test05(){
        SqlSession sqlSession = CommonMethod.getSqlSession();
        RegInfoDao regInfoDao = sqlSession.getMapper(RegInfoDao.class);
        RegInfo reg = regInfoDao.findRegInfoById(1);
        sqlSession.close();
        System.out.println(reg);
    }
    @Test
    public void test06(){
        SqlSession sqlSession = CommonMethod.getSqlSession();
        AdminDao adminDao = sqlSession.getMapper(AdminDao.class);
        List<V_Admin> va = adminDao.findAdminByPage("z", 1, "2020-1-1", "2021-12-1", new RowBounds(0, 5));
        Integer z = adminDao.findCountAdminByPage("z", 1, "2020-1-1", "2021-12-1");
        System.out.println(va);
        System.out.println(z);
    }
    @Test
    public void test07(){
        SqlSession sqlSession = CommonMethod.getSqlSession();
        FileTypeDao fileTypeDao = sqlSession.getMapper(FileTypeDao.class);
        Integer countFileTypeByPage = fileTypeDao.findCountFileTypeByPage("", 0, 0);
        System.out.println(countFileTypeByPage);
    }
    @Test
    public void test08(){
        ApplicationContext ac =new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
        AdminService adminService = ac.getBean(AdminService.class);
        Admin admin = new Admin();
        admin.setAdminName("lisi");
        admin.setAdminPwd("123456");
        Admin login = adminService.login(admin);
        System.out.println(login);
    }
}
